# ------------------------------------------------------------------------------
# Makes targets for 07_limited_bandwidth_models/02_behavioral_gbm directory
# Author: Cassidy Shubatt <cshubatt@gmail.com>
# To run: bsub -q big -R "rusage[mem=150000]" make
# ------------------------------------------------------------------------------

# Config -----------------------------------------------------------------------
.ONESHELL:
include config.mk

# Recipes ----------------------------------------------------------------------
## all			: Produces all targets for GBM limited bandwidth pipeline
.PHONY: all
all: performance_plot

# Intermediate recipes
$(COHORT): ../../02_prep_and_summarize_cohort/
	$(MAKE) -C ../../02_prep_and_summarize_cohort

## gbms			: Produces 100 gbms to predict Y in train set
.PHONY: gbms
gbms: $(GBMS)
$(GBMS): 01_fit_gbms.sh scripts/01_fit_gbms.R $(COHORT)
	bash $<

$(PERFORMANCE_ALL): 02_predict_gbms.sh scripts/02_predict_gbms.R $(GBMS)
	bash $<

## performance		: Gets performance summary for each complexity level
.PHONY: performance
performance: $(PERFORMANCE_SUM)
$(PERFORMANCE_SUM): 03_summarize_performance.sh \
scripts/03_summarize_performance.R $(PERFORMANCE_ALL)
	bash $<

# Results recipes
## performance_plot	: Plots performance (AUC, R2) of gbms to predict Y,T
.PHONY: performance_plot
performance_plot:  $(PERFORMANCE_PLOT)
$(PERFORMANCE_PLOT): 04_plot_performance.sh scripts/04_plot_performance.R \
$(PERFORMANCE_SUM)
	bash $<

# Config targets ---------------------------------------------------------------
## dirs 			: Builds all directories.
.PHONY : dirs
dirs : $(DIRS)
%/.f :
	mkdir -p $(dir $@)
	touch $@

## style			: Styles R scripts according to tidyverse guidelines
.PHONY: style
style:
	source ~/anaconda3/etc/profile.d/conda.sh
	conda activate stressr
	R --vanilla --silent -e "styler::style_dir(path = 'scripts', filetype = c('R', 'Rmd', 'Rprofile'))"

## clean			: Deletes all output.
.PHONY : clean
clean :
	rm -rf temp

.PHONY : help
help : Makefile
	@sed -n 's/^##//p' $<
